package com.yzt.zhuju.arouter;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.core.LogisticsCenter;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.launcher.ARouter;
import com.yzt.p_base.utils.ToastUtil;
import com.yzt.zhuju.RXingUtils;
import com.yzt.zhuju.utils.ActivityManagerUtils;

/**
 * author : bob
 * date   : 2022/11/30
 * desc   :
 */
public class RouterMessage {

    //消息主页
    public static final String FRAGMENT_MESSAGE = "/message/MessageFatherFragment";

    //消息列表
    public static final String ACTIVITY_MESSAGE_LIST = "/messageList/MessageListActivity";

    //聊天页面
    public static final String ACTIVITY_CONVERSITY = "/message/ConversationActivity";

    //系统消息
    public static final String ACTIVITY_SYSMSG = "/message/SystemMessageActivity";

    //系统消息
    public static final String ACTIVITY_SYSMSG_DETAIL = "/message/SystemMessageDetailActivity";

    //未回复消息主页
    public static final String FRAGMENT_NOT_REPLY_MESSAGE = "/message/NotReplyMessageActivity";

    /**
     * 主页消息页面
     */
    public static Fragment MessageFatherFragment() {
        return (Fragment) ARouter.getInstance().build(FRAGMENT_MESSAGE).navigation();
    }

    /**
     * 未回复消息页面
     */
    public static void NotReplyMessageActivity(String title) {
        ARouter.getInstance().build(FRAGMENT_NOT_REPLY_MESSAGE)
                .withString("title", title)
                .navigation();
    }

    /**
     * 系统消息
     */
    public static void SystemMessageDetailActivity(String title) {
        ARouter.getInstance().build(ACTIVITY_SYSMSG_DETAIL)
                .withString("title", title)
                .navigation();
    }

    /**
     * 跳转会话页面
     */
    public static void ConversationActivity(String hisAccid, String hisNickName, int displayMode, boolean isGroup) {

        if (hisAccid == null) {
            return;
        }

        if (RXingUtils.getUserId() == null) {
            return;
        }

        if (hisAccid.equals(RXingUtils.getUserId())) {
            ToastUtil.showMessage("不可以给自己发消息哦");
            return;
        }

        ActivityManagerUtils.getInstance().finishActivity("com.nomichat.message.activity.ConversationActivity");

        ARouter.getInstance().build(ACTIVITY_CONVERSITY)
                .withString("mHisAccid", hisAccid)
                .withString("mHisNickname", hisNickName)
                .withInt("displayMode", displayMode)
                .withBoolean("isGroup", isGroup)
                .navigation();
    }

    public static void ConversationActivity(String hisAccid, String hisNickName, boolean isGroup) {
        ConversationActivity(hisAccid, hisNickName, 0, isGroup);
    }

    public static String getMessageListActivityClassAllPathName() {
        Postcard build = ARouter.getInstance().build(ACTIVITY_MESSAGE_LIST);
        LogisticsCenter.completion(build);
        if (build.getDestination() != null) {
            //p.getDestination()是一个class，即路径指向的activity
            return build.getDestination().getName();
        }
        return "MessageListActivity";
    }

    /**
     * 系统消息
     */
    public static void SystemMessageActivity(String mType, String mTitleName, int conversationType) {
        ARouter.getInstance()
                .build(ACTIVITY_SYSMSG)
                .withString("mType", mType)
                .withInt("conversationType", conversationType)
                .withString("mTitleName", mTitleName)
                .navigation();
    }
}
